package Server.ServerMainFrame.ServerMainFrameModel;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import Core.Model.*;

import Server.ServerMainFrame.ServerMainFrameModel.*;

public class InitializeClientAccount 
{
    public InitializeClientAccount(ServerMainFrameModel model)
    {
    	this.model = model;
    	initializeClientAccount();
    }
    public void initializeClientAccount()
    {
    	try
    	{
    		BufferedReader in = new BufferedReader(new FileReader(this.model.clientInfromationConfigureFile));
    	
    		for (this.model.ClientNumber = 1; ;this.model.ClientNumber++)
    		{
    			String userName = in.readLine();
    			String password = in.readLine();
    			if (userName == null || password == null)  break;
    			ClientType clientType = ClientType.valueOf(in.readLine());
    			if (clientType == null)  break;
    			System.out.println(userName + "  "+ password + " " + clientType);
    			this.model.clientUser[this.model.ClientNumber] = new ClientUser(userName, password, clientType);
    		}
    		this.model.ClientNumber--;
    	}
    	catch(FileNotFoundException exception)
    	{
    		System.out.println("FileNotFound when initializeTeamUserInfromation");
    	}
    	catch(IOException exception)
    	{
    	   System.out.println("IOException when initializeTeamUserInfromation");	
    	}
    }
    private ServerMainFrameModel model;    
}
